<template>
  <div class="swiper-container" :ref="swiperRef">
    <div class="swiper-wrapper">
      <div
        class="swiper-slide"
        v-for="(banner, index) in bannerList"
        :key="banner.id"
      >
        <img :src="banner.imgUrl" />
      </div>
    </div>
    <div class="swiper-pagination"></div>
    <div class="swiper-button-prev"></div>
    <div class="swiper-button-next"></div>
  </div>
</template>

<script>
import Swiper from "swiper";
export default {
  name: "SliderLoop",
  props:['bannerList','swiperRef'],
  watch: {
    bannerList: {
      immediate: true,
      handler(newVal, oldVal) {
        //数据回来了但是，数据回来了我们页面上是需要使用数据来生成div结构
        // div结构还没有生成完成，下面就开始new了，所以，new还是造了

        // this.$nextTick(callback)
        // 这个方法：等待页面最近一次更新完成再去执行回调
        this.$nextTick(() => {
          // this.$refs.bannerSwiper
          new Swiper(this.$refs[this.swiperRef], {
            // 如果需要分页器
            
            pagination: {
              el: ".swiper-pagination",
              clickable:true,
            },
            // 如果需要前进后退按钮
            navigation: {
              nextEl: ".swiper-button-next",
              prevEl: ".swiper-button-prev",
            },
          });
        });
      },
    },
  },
};
</script>

<style lang="less" scoped>
</style>
